/**
 * <copyright>
 * </copyright>
 *

 */
package it.spoli.talkMe.impl;

import it.spoli.talkMe.Interaction;
import it.spoli.talkMe.Message;
import it.spoli.talkMe.Subject;
import it.spoli.talkMe.Support;
import it.spoli.talkMe.TalkMePackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Interaction</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link it.spoli.talkMe.impl.InteractionImpl#getSender <em>Sender</em>}</li>
 *   <li>{@link it.spoli.talkMe.impl.InteractionImpl#getMsg <em>Msg</em>}</li>
 *   <li>{@link it.spoli.talkMe.impl.InteractionImpl#getReceiver <em>Receiver</em>}</li>
 *   <li>{@link it.spoli.talkMe.impl.InteractionImpl#getSupport <em>Support</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class InteractionImpl extends MinimalEObjectImpl.Container implements Interaction
{
  /**
   * The cached value of the '{@link #getSender() <em>Sender</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSender()
   * @generated
   * @ordered
   */
  protected Subject sender;

  /**
   * The cached value of the '{@link #getMsg() <em>Msg</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMsg()
   * @generated
   * @ordered
   */
  protected Message msg;

  /**
   * The cached value of the '{@link #getReceiver() <em>Receiver</em>}' reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getReceiver()
   * @generated
   * @ordered
   */
  protected Subject receiver;

  /**
   * The cached value of the '{@link #getSupport() <em>Support</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSupport()
   * @generated
   * @ordered
   */
  protected Support support;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected InteractionImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return TalkMePackage.Literals.INTERACTION;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Subject getSender()
  {
    if (sender != null && sender.eIsProxy())
    {
      InternalEObject oldSender = (InternalEObject)sender;
      sender = (Subject)eResolveProxy(oldSender);
      if (sender != oldSender)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, TalkMePackage.INTERACTION__SENDER, oldSender, sender));
      }
    }
    return sender;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Subject basicGetSender()
  {
    return sender;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setSender(Subject newSender)
  {
    Subject oldSender = sender;
    sender = newSender;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, TalkMePackage.INTERACTION__SENDER, oldSender, sender));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Message getMsg()
  {
    if (msg != null && msg.eIsProxy())
    {
      InternalEObject oldMsg = (InternalEObject)msg;
      msg = (Message)eResolveProxy(oldMsg);
      if (msg != oldMsg)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, TalkMePackage.INTERACTION__MSG, oldMsg, msg));
      }
    }
    return msg;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Message basicGetMsg()
  {
    return msg;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMsg(Message newMsg)
  {
    Message oldMsg = msg;
    msg = newMsg;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, TalkMePackage.INTERACTION__MSG, oldMsg, msg));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Subject getReceiver()
  {
    if (receiver != null && receiver.eIsProxy())
    {
      InternalEObject oldReceiver = (InternalEObject)receiver;
      receiver = (Subject)eResolveProxy(oldReceiver);
      if (receiver != oldReceiver)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, TalkMePackage.INTERACTION__RECEIVER, oldReceiver, receiver));
      }
    }
    return receiver;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Subject basicGetReceiver()
  {
    return receiver;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setReceiver(Subject newReceiver)
  {
    Subject oldReceiver = receiver;
    receiver = newReceiver;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, TalkMePackage.INTERACTION__RECEIVER, oldReceiver, receiver));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Support getSupport()
  {
    return support;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetSupport(Support newSupport, NotificationChain msgs)
  {
    Support oldSupport = support;
    support = newSupport;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TalkMePackage.INTERACTION__SUPPORT, oldSupport, newSupport);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setSupport(Support newSupport)
  {
    if (newSupport != support)
    {
      NotificationChain msgs = null;
      if (support != null)
        msgs = ((InternalEObject)support).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TalkMePackage.INTERACTION__SUPPORT, null, msgs);
      if (newSupport != null)
        msgs = ((InternalEObject)newSupport).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TalkMePackage.INTERACTION__SUPPORT, null, msgs);
      msgs = basicSetSupport(newSupport, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, TalkMePackage.INTERACTION__SUPPORT, newSupport, newSupport));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case TalkMePackage.INTERACTION__SUPPORT:
        return basicSetSupport(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case TalkMePackage.INTERACTION__SENDER:
        if (resolve) return getSender();
        return basicGetSender();
      case TalkMePackage.INTERACTION__MSG:
        if (resolve) return getMsg();
        return basicGetMsg();
      case TalkMePackage.INTERACTION__RECEIVER:
        if (resolve) return getReceiver();
        return basicGetReceiver();
      case TalkMePackage.INTERACTION__SUPPORT:
        return getSupport();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case TalkMePackage.INTERACTION__SENDER:
        setSender((Subject)newValue);
        return;
      case TalkMePackage.INTERACTION__MSG:
        setMsg((Message)newValue);
        return;
      case TalkMePackage.INTERACTION__RECEIVER:
        setReceiver((Subject)newValue);
        return;
      case TalkMePackage.INTERACTION__SUPPORT:
        setSupport((Support)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case TalkMePackage.INTERACTION__SENDER:
        setSender((Subject)null);
        return;
      case TalkMePackage.INTERACTION__MSG:
        setMsg((Message)null);
        return;
      case TalkMePackage.INTERACTION__RECEIVER:
        setReceiver((Subject)null);
        return;
      case TalkMePackage.INTERACTION__SUPPORT:
        setSupport((Support)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case TalkMePackage.INTERACTION__SENDER:
        return sender != null;
      case TalkMePackage.INTERACTION__MSG:
        return msg != null;
      case TalkMePackage.INTERACTION__RECEIVER:
        return receiver != null;
      case TalkMePackage.INTERACTION__SUPPORT:
        return support != null;
    }
    return super.eIsSet(featureID);
  }

} //InteractionImpl
